<?php

namespace App\Http\Controllers\Admin;
use App\DTOS\Admin\UserRoleDTO;
use App\Http\Controllers\Controller;
use App\Models\Game\CashMonitor;
use App\Models\Game\CashMonitorList;
use App\Models\Game\Equip;
use App\Models\Game\Server;
use App\Models\Game\UserRole;
use App\Services\Game\UserMemberService;
use App\Services\Game\UserRoleService;
use App\Utils\MyLog;
use App\Utils\ResponseUtil;
use Illuminate\Http\Request;

class PvpLogController extends Controller
{
    private Request $request;
    private UserRoleService $userRoleService;
    private UserMemberService $userMemberService;

    /**
     * EquipmentController constructor.
     * @param Request $request
     * @param UserRoleService $userRoleService
     * @param UserMemberService $userMemberService
     */
    public function __construct(Request $request, UserRoleService $userRoleService, UserMemberService $userMemberService)
    {
        $this->request = $request;
        $this->userRoleService = $userRoleService;
        $this->userMemberService = $userMemberService;
    }

    public function paginate(){ //查询ES数据库
        global $gameArea;
        $params = request()->all();
        $roleName = data_get($params,'roleName');
        $gameArea = data_get($params,'gameArea');

        $result = callRpc('/PvpLogsService/paginate',$params,['gameArea'=>$gameArea]);
        MyLog::info('服务器ID'.json_encode($gameArea));
        if($gameArea!=="901"){
            if (isset($result['data'])) {
                foreach ($result['data'] as &$datum) {
                    $model = UserRole::query()->where('id',$datum["Atk"])->first();
                    if ($model) {
                        $datum['Atkname'] = $model->nick;
                        // 在这里使用 $nick 进行你需要的操作
                    }
                    $model1 = UserRole::query()->where('id',$datum["Def"])->first();
                    if ($model1) {
                        $datum['Defname'] = $model1->nick;
                        // 在这里使用 $nick 进行你需要的操作
                    }
                }
            }
        }

        return ResponseUtil::json($result);
    }


    private function actionTypeName($actionType){
        switch($actionType){
            case 1: return '使用';
            case 2: return '精灵转生';
            case 3: return '精灵进化';
            case 4: return '精灵属性洗练';
            case 5: return '精灵技能洗练';
            case 6: return '精灵仓库学习';
            case 7: return '精灵仓库开格';
            default: return '';
        }
    }

}
